import { loadPlugin, loadPluginFn } from '../../app/config/loadplugin.config.js';
import authService from '../../app/resolves/authService.js';
import getRaceList from '../resolves/getRaceList.js';
import getRaceDetail from '../resolves/getRaceDetail.js';
import getDistrict from '../resolves/getDistrict.js';
import getCourseList from '../../../modules/course/resolves/getCourseList.js';
import getCpList from '../../../modules/cp/resolves/getCpList.js';

import raceHtml from 'ngtemplate!html!../../../tpls/race/race.html';
import raceListHtml from 'ngtemplate!html!../../../tpls/race/race.list.html';
import raceIndexHtml from 'ngtemplate!html!../../../tpls/race/race.index.html';
import raceContentHtml from 'ngtemplate!html!../../../tpls/race/race.content.html';
import raceInfoHtml from 'ngtemplate!html!../../../tpls/race/race.info.html';
import raceDetailHtml from 'ngtemplate!html!../../../tpls/race/race.detail.html';


/**
 * AppConfig - config
 * 赛事模块路由设置
 */
RaceRouter.$inject = ['$stateProvider', '$urlRouterProvider', '$httpProvider', '$locationProvider', '$ocLazyLoadProvider'];
function RaceRouter($stateProvider, $urlRouterProvider, $httpProvider, $locationProvider, $ocLazyLoadProvider) {

	//set router
    $stateProvider

		// 赛事创建
		.state('dashboard.create', {
		    url: '/race/create?company_id',
		    data: { 
		        pageTitle: '新建赛事' 
		    },
		    templateUrl: raceHtml,
		    controller: 'RaceCreateController as vm',
		    resolve: {
		    	authService: authService,
		    	loadPlugin: loadPluginFn([loadPlugin.locale, loadPlugin.moment, loadPlugin.icheck, loadPlugin.blink])
            }
		})

    	// 赛事列表
    	.state('dashboard.list', {
		    url: '/race/list?company_id',
		    data: { 
		        pageTitle: '赛事列表' 
		    },
		    templateUrl: raceListHtml,
		    controller: 'RaceListController as vm',
		    resolve: {
		    	authService: authService, 
		    	getRaceList: getRaceList,
		    	loadPlugin: loadPluginFn([loadPlugin.grumble, loadPlugin.imglazy])
		    }
		})

    	// 编辑赛事
		.state('dashboard.edit', {
		    url: '/race/edit?company_id&race_id',
		    data: { 
		        pageTitle: '编辑赛事' 
		    },
		    templateUrl: raceHtml,
		    controller: 'RaceEditController as vm',
		    resolve: {
		    	authService: authService,
		    	getRaceDetail: getRaceDetail,
		    	getDistrict: getDistrict,
                loadPlugin: loadPluginFn([loadPlugin.locale, loadPlugin.moment, loadPlugin.icheck, loadPlugin.blink])
            }
		})
		
		// 赛事管理
		.state('dashboard.race', {
			abstract: true,
		    url: '/race?company_id&race_id',
		    data: { 
		        pageTitle: '赛事管理' 
		    },
		    templateUrl: raceIndexHtml,
		    controller: 'NavigationController',
		    resolve: {
		    	getRaceDetail: getRaceDetail,
		    	loadPlugin: loadPluginFn([loadPlugin.qrcode, loadPlugin.clipboard, loadPlugin.moment, loadPlugin.flot, loadPlugin.angles])
		    }
		})

		// 赛事管理主页
		.state('dashboard.race.index', {
		    url: '/index',
		    data: { 
		        pageTitle: '赛事管理' 
		    },
		    templateUrl: raceContentHtml,
		    controller: 'NavigationController',
		    resolve: {
		    	authService: authService,
		    	getRaceDetail: getRaceDetail,
		    	loadPlugin: loadPluginFn([loadPlugin.qrcode, loadPlugin.clipboard, loadPlugin.moment, loadPlugin.flot, loadPlugin.angles])
		    }
		})

		// 赛事管理基本信息
		.state('dashboard.race.basic', {
		    url: '/basic',
		    data: { 
		        pageTitle: '基本信息' 
		    },
		    templateUrl: raceInfoHtml,
		    controller: 'RaceEditController as vm',
		    resolve: {
		    	authService: authService,
		    	getRaceDetail: getRaceDetail,
		    	getDistrict: getDistrict,
                loadPlugin: loadPluginFn([loadPlugin.locale, loadPlugin.moment, loadPlugin.icheck, loadPlugin.blink, loadPlugin.umeditor])
            }
		})

		// 赛事管理详情信息
		.state('dashboard.race.detail', {
		    url: '/detail',
		    data: { 
		        pageTitle: '详情信息' 
		    },
		    templateUrl: raceDetailHtml,
		    controller: 'RaceDetailController as vm',
		    resolve: {
		    	getCourseList: getCourseList,
		    	getCpList: getCpList,
                loadPlugin: loadPluginFn([loadPlugin.icheck])
            }

		});

}

export default RaceRouter;